/**
 * 
 */
package com.fox.webapp.web.admin;

import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.fox.webapp.service.IAdminService;
import com.fox.webapp.utils.Constant;

/**
 * @author yockii
 *
 */
@Controller
@RequestMapping("admin")
public class AdminController {
	private static final Logger logger = LoggerFactory.getLogger(AdminController.class);
	@Autowired
	private IAdminService adminService;
	
	@RequestMapping(value = "login.yockii", method = RequestMethod.GET)
	public String loginPage(){
		return "admin/login";
	}
	
	@RequestMapping(value = "login.yockii", method = RequestMethod.POST)
	public String doLogin(HttpSession session, String username, String password){
		if (adminService.adminLogin(username, password)) {
			session.setAttribute(Constant.SESSION_ADMIN, username);
			return "redirect:/admin/main";
		}
		return "redirect:/admin/login.yockii";
	}
	
	@RequestMapping(value = "main", method = RequestMethod.GET)
	public String mainPage(){
		return "admin/main";
	}
	
}
